<?php
    use User\Model\ActivityModel;
?>
<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                活动详情
            </header>
            <div class="panel-body">
                <form class="form-horizontal" method="post"
                      action="<?php if($type=='add'){echo '/User/Activityds/add';}
                      else{echo '/User/Activityds/update';}?>" style="width: 70%;" >
                    <input type="hidden" value="<?php $val = (!empty($activity)) ?
                            $activity['act_id'] : ''; echo $val;?>" name="actId">
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label need">名称:</label>

                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="name" value="<?php $val=(!empty($activity)) ?
                            $activity['name'] : ''; echo $val;?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label ">开始时间</label>
                        <div class="col-sm-10">
                            <input class="form-control date-picker" id="start" name="start_date" value="<?php $val=(!empty($activity)) ?
                            $activity['start_date'] : ''; echo $val;?>" placeholder="请输入活动开始时间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label ">结束时间</label>
                        <div class="col-sm-10">
                            <input class="form-control date-picker" id="end" name="end_date" value="<?php $val=(!empty($activity)) ?
                            $activity['end_date'] : ''; echo $val;?>" placeholder="请输入活动结束时间">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button class="btn btn-primary" type="submit" id="submit">提交</button>
                            <button class="btn btn-default" type="button" onclick="history.back(-1);">取消</button>
                        </div>
                    </div>

                </form>
            </div>
        </section>
    </div>
</div>
<script>
    $(".need").each(function(){
        $(this).prepend("<span style='color:red'>*</span>");
    });
    $("#submit").click(function(){
        var data = $("form").serialize();
        var url = $("form").attr("action");
        $.ajax({
            type:'post',
            dataType:'json',
            data:data,
            url:url,
            success:function(res){
                if(res.code == 1){
                    alert("提交成功");
                    window.location = '/User/Activityds/index';
                }else{
                    alert(res.msg);
                }
            }
        });
        return false;
    });
</script>
<script type="text/javascript" src="/Public/js/laydate/laydate.js"></script>
<script type="text/javascript">
    var start = {
        elem: '#start',
        format: 'YYYY/MM/DD hh:mm:ss',
        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY/MM/DD hh:mm:ss',
        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    laydate.skin( "molv" );
</script>